<?php
//
// ClassesModule.class.php
//

// Direct access protection
if( !defined( 'LIRIOPE' )) die( 'Direct access is not allowed.' );

class ClassesModule Extends LiriopeModule {

  // show()
  // displays a list of the latest blog posts
  //
  public function show( $vars=NULL ) {
    global $module;
    $page = a::get($vars, 'page');

    // Hold the name of the custom view file if one was passed
    // look for a custom view
    if( a::get($vars, 'template')) {
      $template = a::get($vars, 'template');
      $seek = $this->_controller . '/_' . $this->_action . '-' . basename($template) . '.php';
      $customView = load::exists( $seek );
      $module->_theme = $customView;
    }

    $classes = new Classes( a::get($vars, 'yaml'));

    $module->classes = $classes->get();
  }

  // details()
  // displays the details for a class
  // if the event data is an array, then it lists coming classes
  //
  public function details( $vars=NULL ) {
    global $module;
    $classes = new Classes( a::get($vars, 'yaml'));
    $class = $classes->getByID(a::get($vars, 'id'));
    $module->class = $class->getName();
    $module->event = $class->getNextEvent();
    $module->date  = $class->getNextEventDate();
    // TODO: dates works in the view, but date doesn't... curious
    $module->dates = $class->getNextEventDate();
    $module->notes = $class->getEventNotes();
  }

  // upcoming()
  // displays the following scheduled classes for an event by id
  //
  public function upcoming( $vars=NULL ) {
    global $module;
    $classes = new Classes( a::get($vars, 'yaml'));
    $class = $classes->getByID(a::get($vars, 'id'));
    $events = $class->getUpcomingEvents();
    $module->upcoming = $events;
  }

}

?>
